package com.ybb.account.service;

import com.ybb.account.mapper.MerchantAccountChangeMapper;
import com.ybb.account.mapper.MerchantAccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service
public class MerchantAccountServiceImpl implements MerchantAccountService {

    @Autowired
    private MerchantAccountMapper merchantAccountMapper;

    @Autowired
    private MerchantAccountChangeMapper merchantAccountChangeMapper;



    /**
     * 锁住并返回用户帐户余额
     */
    public void enchargeAccount(String merchantCode, Double amount){
        //记录商家的账户变化
        merchantAccountChangeMapper.insertChange(merchantCode,amount);
        //变更商家账户
        merchantAccountMapper.enchargeAccount(merchantCode, amount);
    }

    public Map<String,Double> settleMerchantBalance(Date start, Date end){
        return merchantAccountMapper.settleMerchantBalance(start, end);
    }
}
